package com.star.niuke;

import java.util.Stack;

/**
 * @author: liminghui
 * @date: 2021/7/24 15:40
 * @version: 1.0
 * @description: 用两个栈实现队列
 */
public class StackList {

    public static void main(String[] args) {
        StackList stackList = new StackList();
        stackList.push(1);
        stackList.push(2);
        int pop1 = stackList.pop();
        int pop2 = stackList.pop();
        System.out.println("pop1="+pop1);
        System.out.println("pop2="+pop2);
    }

    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.push(node);
    }

    public int pop() {
        if (stack2.empty()) {
            while (!stack1.empty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }


}
